﻿using UnityEngine;
using System.Collections.Generic;

namespace BehaviorSystem
{
    public class BehaviourManager : IBehaviourManager
    {
        List<IBehaviorAgent> behaviorAgents = new List<IBehaviorAgent>();

        public void InitBehaviourTick()
        {
            GameObject go = new GameObject("BehaviourTicker");
            BehaviourTicker ticker= go.AddComponent<BehaviourTicker>();
            MonoBehaviour.DontDestroyOnLoad(go);
            ticker.TickEvent += Tick;
        }

        public void RegisterBehaviourAgent(IBehaviorAgent agent)
        {
            if (!behaviorAgents.Contains(agent))
            {
                behaviorAgents.Add(agent);
            }
        }

        public void Tick()
        {
            for (int i = 0; i < behaviorAgents.Count; i++)
            {
                behaviorAgents[i].Tick();
            }
        }
    }
}
